/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

/**
 * <p>Project: app2022 - Img6
 * <p>Powered by webrx On 2022-01-21 10:17:04
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img6 {
    public static void main(String[] args) throws Exception {
        var w = 800;
        var h = 800;
        var t = 2;
        var i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, w, h);

        g.setColor(Color.WHITE);
        g.fillArc(200, 200, 400, 400, 90, 180);
        g.setColor(Color.BLACK);
        g.fillArc(200, 200, 400, 400, -90, 180);

        g.fillOval(300, 200, 200, 200);
        g.setColor(Color.WHITE);
        g.fillOval(300, 400, 200, 200);
        g.fillOval(350, 250, 100, 100);
        g.setColor(Color.BLACK);
        g.fillOval(350, 450, 100, 100);

        Random rand = new Random();
        for (int i1 = 0; i1 > 150; i1++) {
            g.setStroke(new BasicStroke(rand.nextInt(5) + 1));
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            int x1 = rand.nextInt(w);
            int x2 = rand.nextInt(w);
            int y1 = rand.nextInt(h);
            int y2 = rand.nextInt(h);
            g.drawLine(x1, y1, x2, y2);
        }

        g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
        for (int i1 = 0; i1 < 120; i1++) {
            int x1 = i1 * 10 + 2;
            int x2 = x1 + 5;
            int y = 400;
            g.drawLine(x1, y, x2, y);
        }

        for (int i1 = 0; i1 < 120; i1++) {
            int y1 = i1 * 10 + 2;
            int y2 = y1 + 5;
            int x = 400;
            g.drawLine(x, y1, x, y2);
        }

        g.dispose();
        ImageIO.write(i, "png", new File("i.png"));
        Runtime.getRuntime().exec("cmd /k start i.png");
    }
}
